/*
 * @Author: your name
 * @Date: 2020-12-11 17:47:09
 * @LastEditTime: 2021-01-05 17:19:19
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \myReposCode\Verification\encoded.cpp
 */
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>

using namespace std;

// write data to file using <<
void test()
{
    std::ofstream ofs;
    ofs.open("encoded.bin", std::ios::out | std::ios::trunc);
    const char * str = "ILoveC";
    int a = 2;
    // double b = 12345.123456789;
    ofs << str << a;
    // ofs << str << a << b;
    ofs.close();
}

// write data in memory to bin file using write()
void test01()
{
    std::ofstream ofs;
    ofs.open("encoded01.bin", std::ios::out | std::ios::binary | std::ios::trunc);
    const char * str = "ILoveC";
    ofs.write(str, strlen(str));
    int a = 2;
    // double b = 12345.123456789;
    ofs.write((char *)&a, sizeof(a));
    // ofs.write((char *)&b, sizeof(b));
    ofs.close();
}

void test02()
{
    std::ofstream ofs;
    ofs.open("testlong.bin", std::ios::out | std::ios::binary | std::ios::trunc);
    long long var = 2;
    ofs.write((char *)&var, sizeof var);
    var = 123456789;
    ofs.write((char *)&var, sizeof var);
    ofs.close();
}

int main()
{
    // test();
    // test01();
    test02();
    return 0;
}